package train48days;

import java.util.Scanner;
import java.util.Stack;

/**
 * 后缀表达式也叫逆波兰表达式 2+3 == 2 3 +；
 */
public class Emacs计算器 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n =sc.nextInt();
            String s = "";
            Stack<Integer> stack = new Stack<>();
            for (int i = 0; i < n; i++) {
                s=sc.next();
                char c = s.charAt(0);
                if (!(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/"))){
                    stack.add(Integer.parseInt(s));
                }else {
                    int right = stack.pop();
                    int left=stack.pop();

                    switch (c){
                        case '+':
                            stack.add(left+right);
                            break;
                        case '-':
                            stack.add(left-right);
                            break;
                        case '*':
                            stack.add(left*right);
                            break;
                        case '/':
                            stack.add(left/right);
                            break;
                    }
                }
            }
            System.out.println(stack.pop());
        }
    }
}
